package com.yhyvr.console.controller;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.StringUtil;
import com.yhyvr.console.annotation.RepeatSubmit;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.lz.kit.LogKit;
import com.lz.tool.LzStringUtils;
import com.yhyvr.pojo.resp.console.BootStrapGridResp;
import com.yhyvr.console.model.login.LoginUserModel;
import com.lz.mybatis.jdbc.auto.dao.BoCommentMapper;
import com.lz.mybatis.jdbc.auto.model.BoComment;
import com.lz.mybatis.jdbc.auto.model.BoCommentExample;
import com.yhyvr.pojo.resp.CommonResp;
import com.yhyvr.pojo.resp.HttpResult;
import com.yhyvr.pojo.req.console.BootStrapGridReq;
import com.yhyvr.console.controller.ControllerQueryTool;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * title:
 * </p>
 * <p>
 * description:
 * </p>
 *
 * @create 张钦
 * @update
 * @version 1.0
 * @date
 */
@Controller
public class BoCommentController{
	@Resource
	private BoCommentMapper modelMapper;


	@RepeatSubmit(isAdd = true)
	@RequestMapping("/console/bo_comment/edit")
	public String edit(ModelMap modelMap,String id){
			modelMap.put("boComment", modelMapper.selectByPrimaryKey(id));
		return "console/boComment/boComment_form";
	}

	@RequestMapping("/console/bo_comment/list")
	public String list(){
		return "console/boComment/boComment_table";
	}

	@RequestMapping("/console/bo_comment/json")
	public @ResponseBody BootStrapGridResp json(BootStrapGridReq bootGridReq){
		Page page = PageHelper.offsetPage(bootGridReq.getOffset(), bootGridReq.getLimit());
    	if(bootGridReq.getSort()!=null) {
    		page.setOrderBy(LzStringUtils.chageStringUpCaseAnd_(bootGridReq.getSort()) + " " + bootGridReq.getOrder());
    	}
		BoCommentExample boCommentExample = new BoCommentExample();
        ControllerQueryTool.setBoCommentCriteria(bootGridReq.getQuery(),boCommentExample.createCriteria());
		List<BoComment> boCommentList = modelMapper.selectByExample(boCommentExample);
		return new BootStrapGridResp(page.getTotal(),boCommentList);
	}


	@RequestMapping("/console/bo_comment/delete")
	public @ResponseBody HttpResult delete(String ids){
		String[]idsa=ids.split(",");
		for (String id : idsa) {
		modelMapper.deleteByPrimaryKey(String.valueOf(id));
		}
		return CommonResp.getSuccess();
	}
}
